import GlobalEvent from "../../Global/GlobalEvent";
import goldManager from "../goldManager";

//英雄攻击速度升级管理器
class speedUp {
    private static instance: speedUp;
    private lv: number = 1;
    private addGold: number = 50;
    private addSpeed: number = 1;
    private bool = true;

    private constructor() {
        //从服务器获取用户存储的lv值 更新lv


        //购买的金币 * 购买等级
        this.addGold = this.lv * 50;
        //购买的攻击力 * 购买等级
        this.addSpeed *= this.lv;
    }

    public static getInstance(): speedUp {
        if (!speedUp.instance) {
            speedUp.instance = new speedUp();
        }
        return speedUp.instance;
    }

    public upLv() {
        this.lv++;
    }


    public addgold(): number {
        this.addGold = this.lv * 50;
        return this.addGold;
    }

    public getlv(): number {
        return this.lv;
    }

    public addSpeedFun(): number {
        this.addSpeed = this.lv * 1;
        console.log('addSpeed = ',this.addSpeed);
        
        return this.addSpeed;
    }

    // 如果玩家的金币小于等于0或者小于所需金币，禁用按钮
    public getSpeedBool() {
        let goldMana = goldManager.getInstance();
        // console.log('现在的金币 = ', goldMana.getGold());
        // console.log('购买所需的金币 = ', this.addGold);

        if (goldMana.getGold() <= 0 || goldMana.getGold() < this.addGold) {
            this.bool = false;
            GlobalEvent.emit('getSpeedBoolean', this.bool);
            return;
        } else if (goldMana.getGold() >= this.addGold) {
            // 否则，激活按钮
            this.bool = true;
            GlobalEvent.emit('getSpeedBoolean', this.bool);
            return;

        }

    }
}
export default speedUp;